Flutter 修改源码禁用软键盘(PDA扫码适用) |
您所在的位置:网站首页 › flutter扫码枪 防止软键盘 › Flutter 修改源码禁用软键盘(PDA扫码适用) |
Flutter 因为扫码输入经常弹出软键盘,造成键盘遮挡扫码框,所以需要对dart源码包进行修改,我通过查阅资料找到了相关文档,但是不全,没有修改代码的。所以只能一步一步进行试验。在经过很多次错误后,终于实现textFiled扫码不弹出软键盘。 以下为需要修改的文件的数据 1. text_input.dart 修改后的方法 (1) void show({bool needShow = true}) {//修改的此处 assert(attached); TextInput._instance._show(needShow: needShow);//修改的此处 }(2)修改show方法 void _show({bool needShow = true}) {//修改的此处 assert(needShow);//修改的此处 if (needShow) {//修改的此处 _channel.invokeMethod('TextInput.show');//修改的此处 }2.editable_text.dart 修改的方法 (1)2311行 修改方法 void _openInputConnection() { if (!_shouldCreateInputConnection) { return; } if (!_hasInputConnection) { final TextEditingValue localValue = _value; // When _needsAutofill == true && currentAutofillScope == null, autofill // is allowed but saving the user input from the text field is // discouraged. // // In case the autofillScope changes from a non-null value to null, or // _needsAutofill changes to false from true, the platform needs to be // notified to exclude this field from the autofill context. So we need to // provide the autofillId. _textInputConnection = _needsAutofill && currentAutofillScope != null ? currentAutofillScope! .attach(this, _effectiveAutofillClient.textInputConfiguration) : TextInput.attach( this, _effectiveAutofillClient.textInputConfiguration); _updateSizeAndTransform(); _updateComposingRectIfNeeded(); _updateCaretRectIfNeeded(); final TextStyle style = widget.style; _textInputConnection! ..setStyle( fontFamily: style.fontFamily, fontSize: style.fontSize, fontWeight: style.fontWeight, textDirection: _textDirection, textAlign: widget.textAlign, ) ..setEditingState(localValue) ..show(needShow: needShow);//修改的此处 if (_needsAutofill) { // Request autofill AFTER the size and the transform have been sent to // the platform text input plugin. _textInputConnection!.requestAutofill(); } _lastKnownRemoteTextEditingValue = localValue; } else { _textInputConnection!.show(needShow: needShow);//修改的此处 } }(2)536行 EditableText类属性添加 this.needShow=true,//构造函数里添加 final bool needShow;//添加类属性(3)EditableTextState类方法添加 bool get needShow=>widget.needShow;3 text_field.dart (1)TextField 添加属性 this.needShow = true,//添加构造方法属性 final bool needShow;//添加属性(2)_TextFieldState类添加获取方法 bool get needShow =>widget.needShow;//添加获取方法(3)_TextFieldState build方法添加属性 Widget child = RepaintBoundary( child: UnmanagedRestorationScope( bucket: bucket, child: EditableText( key: editableTextKey, needShow: needShow,//添加属性和方法-----同理TextFormFiled也需要添加needShow属性 4. text_form_field.dart (1)TextFormField添加属性 bool needShow = true,//添加构造方法属性(2)返回方法添加 return UnmanagedRestorationScope( bucket: field.bucket, child: TextField( needShow: needShow,//添加属性 使用时 在textformField对象添加needShow属性 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |